/*
 *
 *      Copyright (c) 2018-2025, cloud All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: cloud
 *
 */

package com.fuyao.cloud.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fuyao.cloud.admin.api.entity.SysDictItem;
import com.fuyao.cloud.admin.service.SysDictItemService;
import com.fuyao.cloud.common.core.constant.CacheConstants;
import com.fuyao.cloud.common.core.util.DictItemOption;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.data.resolver.DictItemResolver;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author cloud
 * @since 2019-03-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dictItem")
@Api(value = "dictItem", tags = "字典管理资源模块")
public class SysDictItemController {

	private final SysDictItemService sysDictItemService;

	@PostMapping("/type/{type}")
	@Cacheable(value = CacheConstants.DICT_DETAILS, key = "#type", unless = "#result.data.isEmpty()")
	public R<Map<String,List<DictItemOption>>> getDictItemByType(@PathVariable String type) {
		return sysDictItemService.listByOptions(Wrappers.<SysDictItem>query().lambda().eq(SysDictItem::getDictType, type));
	}

	@PostMapping("/getDictItemList")
	public R<Map<String,List<DictItemOption>>> getDictItemList(@RequestBody List<String> types) {
		return sysDictItemService.listByOptions(Wrappers.<SysDictItem>query().lambda().in(SysDictItem::getDictType, types));
	}

}
